import Evt from '../event'
import {CN,EN,Web,Cst,UI} from '../config'
import Utils from '../utils'
export default class Plugin extends Evt{
	constructor($event,$env){
		super()
		this.active = false
		this.$env = $env
		this.$event = $event
		this.cn={}
	}
	createLayer(cn="",en){
		if(!this.$layer){
			this.$layer = document.createDOM("div",{
				id:"geo_layer_"+this.ID(),
				class:[CN.layer,cn].join(" ")
			})

			this.$event.emit(en||EN.layout_render,this.$layer)
		}
		return this.$layer
	}
	createClassName(seed){
		if(typeof seed === "string"){
			this.cn[seed] = Web.prefix+"-"+seed+this.ID()
		}else {
			for(let k in seed){
				this.cn[k] = Web.prefix+"-"+seed[k]+this.ID()
			}
		}
	}
	injectStyle(cssText,data,pk){
		data = (data||this.cn)
		Utils.injectStyle(cssText,data.assign(UI),(pk||this.name))
	}
	focusIn(...data){
		this.active = true
		this.emitAsync(Cst.focusIn,...data,this)
		return this
	}
	focusOut(){
		this.active = false
		this.emitAsync(Cst.focusOut,this)
	}
	mixin(mx){
		for(let k in mx)
			this[k] = mx[k]
	}
}